#ifndef MAP_KEYVALUESTORAGE_H_INCLUDED
#define MAP_KEYVALUESTORAGE_H_INCLUDED

#include <Core/SearchEngine/IKeyValueStorage.h>

#include <boost/filesystem.hpp>
#include <boost/unordered_map.hpp>

namespace Core {

/**
 * MapKeyValueStorage in simple implementation of Key-Value storade(in memory)
 * NOTE better is use in memory DB like (trantool or memchache) for such pupose.
 */

typedef boost::unordered_map<std::string, KeyBucket> KeyMap;

class MapKeyValueStorage : public IKeyValueStorage {
public :
	MapKeyValueStorage(KeyValueStorageParams const & params, boost::filesystem::path const & path); 
	~MapKeyValueStorage();
	
	virtual void initialize() throw (std::exception);
	virtual void insert(std::string const & key, KeyBucket const & bucket);
	virtual void remove(std::string const & key);
	virtual bool getBucket(std::string const & key, KeyBucket & bucket);
	virtual bool containsBucket(std::string const & key);

	virtual void getNextKey(std::string & key);
	virtual void getKey(std::string & key, std::size_t index);
	virtual std::size_t getKeyCount();

	virtual unsigned int getKeyMaxLength() { return m_keyMaxLength; }

	KeyValueStorageParams const & getParams() const { return m_baseParams; }

private :
	KeyMap m_signStorage;
	std::vector<std::string> keys;

	KeyValueStorageParams const m_baseParams;
	boost::filesystem::path m_path;
	unsigned int m_keyMaxLength;
	
	void setKeyMaxLength();
	void loadStorage(boost::filesystem::path const & path);

};

typedef boost::shared_ptr<MapKeyValueStorage> MapKeyValueStoragePtr;

void initDefaultMapKeyValueStorage(KeyValueStorageParams const & params, boost::filesystem::path const & path);
MapKeyValueStoragePtr defaultMapKeyValueStorade(); 

} // namespace Core

#endif

